import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
//createWebHistory history
// 路由规则
let routes = [{
        path: '/',//跳转到首页
        name: 'login',
        // 局部路由守卫
        component: () => import("@/views/login.vue")
    }, {
        path: '/home',
        name: 'home',
        component: () => import("@/views/home.vue")
    }, {
        path: '/my',
        name: 'my',
        component: () => import("@/views/my.vue")
    }, {
        path: '/modify',
        name: 'modify',
        component: () => import("@/views/modify.vue")
    }, {
        path: '/showInfo',
        name: 'showInfo',
        component: () => import("@/views/showInfo.vue")
    },
    {
        path: '/canvas',
        name: 'canvas',
        component: () => import("@/views/canvas.vue")
    },
]
const router = createRouter({
    history: createWebHistory(),
    routes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { x: 0, y: 0 }
        }
    },
})

// 路由守卫 必须 调用next
router.beforeEach((to, from, next) => {
    next()
})

export default router
